

package com.maoshi.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.maoshi.shop.common.annotation.SysLog;
import com.maoshi.shop.common.util.PageParam;
import com.maoshi.shop.distribution.comment.model.DistributionProdBind;
import com.maoshi.shop.distribution.comment.service.DistributionProdBindService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 分销商品绑定表
 *
 * @author xwc
 * @date 2019-04-22 10:01:44
 */
@RestController
@RequestMapping("/distribution/distributionProdBind")
@AllArgsConstructor
public class DistributionProdBindController {

    private final DistributionProdBindService distributionProdBindService;

    /**
     * 分页查询
     *
     * @param page                 分页对象
     * @param distributionProdBind 分销商品绑定表
     * @return 分页数据
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<DistributionProdBind>> getDistributionProdBindPage(PageParam<DistributionProdBind> page, DistributionProdBind distributionProdBind) {
        return ResponseEntity.ok(distributionProdBindService.page(page, new LambdaQueryWrapper<DistributionProdBind>()));
    }


    /**
     * 通过id查询分销商品绑定表
     *
     * @param id id
     * @return 单个数据
     */
    @GetMapping("/info/{id}")
    public ResponseEntity<DistributionProdBind> getById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(distributionProdBindService.getById(id));
    }

    /**
     * 新增分销商品绑定表
     *
     * @param distributionProdBind 分销商品绑定表
     * @return 是否新增成功
     */
    @SysLog("新增分销商品绑定表")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionProdBind:save')")
    public ResponseEntity<Boolean> save(@RequestBody @Valid DistributionProdBind distributionProdBind) {
        return ResponseEntity.ok(distributionProdBindService.save(distributionProdBind));
    }

    /**
     * 修改分销商品绑定表
     *
     * @param distributionProdBind 分销商品绑定表
     * @return 是否修改成功
     */
    @SysLog("修改分销商品绑定表")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionProdBind:update')")
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid DistributionProdBind distributionProdBind) {
        return ResponseEntity.ok(distributionProdBindService.updateById(distributionProdBind));
    }

    /**
     * 通过id删除分销商品绑定表
     *
     * @param id id
     * @return 是否删除成功
     */
    @SysLog("删除分销商品绑定表")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionProdBind:delete')")
    public ResponseEntity<Boolean> removeById(@PathVariable Long id) {
        return ResponseEntity.ok(distributionProdBindService.removeById(id));
    }

}
